package com.swz.dcrm.util;


import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created by DELL on 2019/12/23.
 * Desc
 */

public class ConditionUtil {
    private static final String SQL_REGEX = "'|%|--|insert|delete|update|select|count|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql";
    private static final String EQUAL = "EQ_";
    private static final String NOT_EQUAL = "NEQ_";
    private static final String LIKE = "LIKE_";
    private static final String NOT_LIKE = "NOTLIKE_";
    private static final String GT = "GT_";
    private static final String GE = "GTE_";
    private static final String LE = "LTE_";
    private static final String LT = "LT_";
    private static final String IS_NULL = "NULL_";
    private static final String NOT_NULL = "INN_";
    private static final String IN = "IN_";
    private static final String NOT_IN = "NOTIN_";
    private static String[] keywordList = new String[]{EQUAL, NOT_EQUAL, LIKE, NOT_LIKE, GT, GE, LE, LT, IS_NULL, NOT_NULL, IN, NOT_IN};








    private static final String PRIFIX_OR = "orsearch_";
    private static final int PRIFIX_OR_LEN = PRIFIX_OR.length();




    private static boolean isOrParam(String key) {
        return key.startsWith(PRIFIX_OR);
    }






    public static String filter(String param) {
        return param == null ? null : param.replaceAll("(?i)" + SQL_REGEX, "");
    }

    public static Map<String, Object> eq(Map<String, Object> query, String k, Object v) {
        query.put(EQUAL + k, v);
        return query;
    }

    public static Map<String, Object> ne(Map<String, Object> query, String k, Object v) {
        query.put(NOT_EQUAL + k, v);
        return query;
    }

    public static Map<String, Object> like(Map<String, Object> query, String k, Object v) {
        query.put(LIKE + k, v);
        return query;
    }

    public static Map<String, Object> notLike(Map<String, Object> query, String k, Object v) {
        query.put(NOT_LIKE + k, v);
        return query;
    }

    public static Map<String, Object> gt(Map<String, Object> query, String k, Object v) {
        query.put(GT + k, v);
        return query;
    }

    public static Map<String, Object> ge(Map<String, Object> query, String k, Object v) {
        query.put(GE + k, v);
        return query;
    }

    public static Map<String, Object> le(Map<String, Object> query, String k, Object v) {
        query.put(LE + k, v);
        return query;
    }

    public static Map<String, Object> lt(Map<String, Object> query, String k, Object v) {
        query.put(LT + k, v);
        return query;
    }

    public static Map<String, Object> isNull(Map<String, Object> query, String k, Object v) {
        query.put(IS_NULL + k, v);
        return query;
    }

    public static Map<String, Object> isNotNull(Map<String, Object> query, String k, Object v) {
        query.put(NOT_NULL + k, v);
        return query;
    }

    public static Map<String, Object> in(Map<String, Object> query, String k, String v) {
        query.put(IN + k, v);
        return query;
    }

    public static Map<String, Object> in(Map<String, Object> query, String k, Collection v) {
        query.put(IN + k, v);
        return query;
    }

    public static Map<String, Object> notIn(Map<String, Object> query, String k, String v) {
        query.put(NOT_IN + k, v);
        return query;
    }

    public static Map<String, Object> notIn(Map<String, Object> query, String k, Collection v) {
        query.put(NOT_IN + k, v);
        return query;
    }



    public static Map<String, Object> eqOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + EQUAL + k, v);
        return query;
    }

    public static Map<String, Object> neOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + NOT_EQUAL + k, v);
        return query;
    }

    public static Map<String, Object> likeOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + LIKE + k, v);
        return query;
    }

    public static Map<String, Object> notLikeOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + NOT_LIKE + k, v);
        return query;
    }

    public static Map<String, Object> gtOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + GT + k, v);
        return query;
    }

    public static Map<String, Object> geOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + GE + k, v);
        return query;
    }

    public static Map<String, Object> leOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + LE + k, v);
        return query;
    }

    public static Map<String, Object> ltOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + LT + k, v);
        return query;
    }

    public static Map<String, Object> isNullOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + IS_NULL + k, v);
        return query;
    }

    public static Map<String, Object> isNotNullOr(Map<String, Object> query, String k, Object v) {
        query.put(PRIFIX_OR + NOT_NULL + k, v);
        return query;
    }

    public static Map<String, Object> inOr(Map<String, Object> query, String k, Collection v) {
        query.put(PRIFIX_OR + IN + k, v);
        return query;
    }

    public static Map<String, Object> notInOr(Map<String, Object> query, String k, Collection v) {
        query.put(PRIFIX_OR + NOT_IN + k, v);
        return query;
    }



}
